﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>生产领料</title>
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    @* <script src="~/lib/layui/layui.js"></script> *@
    <script src="~/js/js.cookie.js"></script>
    <script src="~/js/moment.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
</head>
<body>
    <!-- 查询条件 -->
    <form class="layui-form" action="">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-input-group">

                    <!-- 领料单编号 -->
                    <div class="layui-input-prefix">
                        <b>领料单编号</b>
                    </div>
                    <div>
                        <input id="pickingNode" type="text" placeholder="请输入领料单编号" class="layui-input" autocomplete="off" lay-affix="clear">
                    </div>

                    <!-- 领料单名称 -->
                    <div class="layui-input-prefix" tyle="left:50px">
                        <b>领料单名称</b>
                    </div>
                    <div>
                        <input id="pickingName" type="text" placeholder="请输入领料单名称" class="layui-input" autocomplete="off" lay-affix="clear">
                    </div>

                    <!-- 仓库名称 -->
                    <div class="layui-input-prefix" tyle="left:50px">
                        <b>仓库名称</b>
                    </div>
                    <div>
                        <input id="x" type="text" placeholder="请输入仓库名称" class="layui-input" autocomplete="off" lay-affix="clear">
                    </div>

                    <!-- 领料日期 -->
                    <div class="layui-input-prefix" tyle="left:50px">
                        <b>领料日期</b>
                    </div>
                    <div style="width:220px;left:43px">
                        <input style="width:210px" type="date" id="pickingTime" value="" placeholder="请输入领料日期" lay-reqtext="请填写领料日期" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>

                    <!-- 单据状态 -->
                    <div class="layui-input-prefix" style="left:50px">
                        <b>单据状态</b>
                    </div>
                    <div style="left:77px;width:197px">
                        <select id="documents" lay-filter="testSelect" autocomplete="off" lay-affix="clear">
                            <option value="">请选择单据状态</option>
                            <option value="1">草稿</option>
                            <option value="2">已确认</option>
                            <option value="3">审批中</option>
                            <option value="4">已审批</option>
                            <option value="5">已完成</option>
                        </select>
                    </div>

                    <!-- 按钮 -->
                    <div class="layui-btn-container layui-col-xs12">
                        <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
                        @*                          <button onclick="PickingLists()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button> *@
                        <button type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>



                </div>
            </div>
        </div>
    </form>
    <br />
    <div>
        <button onclick="Adds()" id="searchBtn" type="button" class="layui-btn layui-btn-normal layui-icon-addition">新增</button>
        <button type="button" class="layui-btn layui-icon-edit" layui-btn-green " >修改</button>
        <button type="button" class="layui-btn layui-bg-red layui-icon-delete">删除</button>
    </div>
    <!-- 表格 -->
    <div>
        <table class="layui-table">
            <colgroup>
                <col width="80">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col width="130">
                <col>
            </colgroup>
            <thead>
                <tr>
                    <th style="text-align:center"><input type="checkbox" name="check" onclick="checkAll()" /></th>
                    <th style="text-align:center">领料单编号</th>
                    <th style="text-align:center">领料单名称</th>
                    <th style="text-align:center">生产工单</th>
                    <th style="text-align:center">工作站</th>
                    <th style="text-align:center">客户编号</th>
                    <th style="text-align:center">客户名称</th>
                    <th style="text-align:center">领料日期</th>
                    <th style="text-align:center">单据状态</th>
                    <th style="text-align:center">操作</th>
                </tr>
            </thead>
            <tbody style="text-align:center">
            </tbody>
        </table>
        <div id="demo-laypage-all"></div>
    </div>

    <!-- HTML Content -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>
        layui.use(['form', 'laydate', 'util', 'table'], function () {
            var form = layui.form;
            var laypage = layui.laypage;
            var layer = layui.layer;
            var $ = layui.$;
            var laydate = layui.laydate;
            var util = layui.util;
            //分页
            var pageIndex = 1;
            var pageSize = 10;
            var pickingNode = "";
            var pickingName = "";
            var pickingTime = null;
            var documents = 0;

            //就绪函数
            $(function () {
                PickingLists(pageIndex, pageSize); //生产领料 显示
            })

            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                PickingLists(pageIndex, pageSize);
                return false; // 阻止默认 form 跳转
            });
            //生产领料 显示
            function PickingLists(pageIndex, pageSize) {
                // console.log(info);
                $.post({
                    url: '@ViewBag.FoundationWrite' + '/api/ProductType/PickingsLists',
                    data: JSON.stringify({
                        pageIndex: pageIndex,
                        pageSize: pageSize,
                        pickingNode: $("#pickingNode").val() || "",
                        pickingName: $("#pickingName").val() || "",
                        pickingTime: $("#pickingTime").val() || null,
                        documents: $("#documents").val() || 0,
                    }),
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)

                        var cont = ""; //定义变量
                        $.each(res.data, function () {
                            cont += `<tr>
                                            <td><input type="checkbox" class="check" value="${this.supplierId}" onclick="checkfan()"/></td>
                                            <td><span style="color:#1e9fff"><b>${this.pickingNode}</b></span></td>
                                            <td>${this.pickingName}</td>
                                            <td>${this.productionWorkOrdersNo}</td>
                                            <td>${this.workStationName}</td>
                                            <td>${this.clientNo}</td>
                                            <td>${this.clientName}</td>
                                            <td>${this.pickingTime.replace("T", " ").substring(0, 19)}</td>
                                            <td>${this.documents === 1 ? '草稿' : (this.documents === 2 ? '已确认' : (this.documents === 3 ? '审批中' : (this.documents === 4 ? '已审批' : '已完成')))}</td>
                                            <td>
                                              <a onclick="PinkAlls('${this.pickingNode}')" style="color:#ff5722"">执行领出</a>
                                              <a onclick="Updates('${this.pickingId}','${this.pickingNode}')" style="color:green"">修改</a>
                                              <a onclick="Steat(0)" style="color:cornflowerblue">审批通过</a>
                                              <a onclick="Steat(1)" style="color:cornflowerblue">审批不通过</a>
                                            </td>
                                        </tr>`
                        })
                        $("tbody").html(cont);
                        console.log(res);
                        // console.log(996, pageSize, pageIndex, res)
                        // 完整显示

                        //完整显示
                        laypage.render({
                            elem: 'demo-laypage-all', // 元素 id
                            count: res.totalCount, // 数据总数
                            curr: pageIndex,//当前页
                            limit: pageSize,//每页几条
                            limits: [2, 3, 4],
                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                            jump: function (obj, first) {
                                if (!first) {
                                    PickingLists(obj.curr, obj.limit);
                                }
                            }
                        });
                        // console.log(996, pickingNode, pickingName, pickingTime, documents,res);
                        //  <a onclick="Updates(${this.pickingId})" class="btn btn-link layui-btn-xs" lay-on="test-page-customsed" style="color:green"">修改</a>
                    }
                });
            };
            PickingLists();

            //弹出层修改写法
            // function Updates(PickingId) {
            //     localStorage['PickingId'] = PickingId;

            //     util.on('lay-on', {
            //         'test-page-customsed': function () {
            //             layer.open({
            //                 type: 2,
            //                 title: '生产领料修改',
            //                 shadeClose: true,
            //                 maxmin: true, //开启最大化最小化按钮
            //                 area: ['1200px', '600px'],
            //                 content: '/Messages/PickingsUpds',
            //             });
            //         },
            //     });
            // }
        });

        //修改生产领料
        function Updates(pickingId, pickingNode) {
            localStorage["pickingNode"] = pickingNode;
            console.log(pickingId, pickingNode);
            localStorage["pickingId"] = pickingId;
            location.href = "/Messages/PickingsUpds?PickingId=" + pickingId;
        };

        //跳转新增
        function Adds() {
            location.href = "/Messages/PickingsCreates";
        }


        //全选反选
        function checkAll() {
            var check = $("[name=check]:eq(0)").prop("checked");
            $("[name=check]:gt(0)").prop("checked", check);
            console.log(check + "123321")
        }
        function checkfan() {
            var length1 = $("[name=check]:gt(0)").length
            var length2 = $("[name=check]:gt(0):checked").length
            var check = lengthl == length2;
            $("[name=check]:eq(0)").prop("checked", check)
        }

        //执行领出
        function PinkAlls(pickingNode) {
            var datec = new Date()
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0")
            var date = (datec.getDate() + 1).toString().padStart(2, "0")
            var hours = datec.getHours()
            var minute = (datec.getMinutes()).toString().padStart(2, "0")
            var seconds = (datec.getSeconds()).toString().padStart(2, "0")
            var result = "ISSUE" + year + month + date + hours + minute + seconds;

            //执行领出友好提示
            if (confirm("确定要执行领出吗?")) {
                var data = {
                    pickingNode: pickingNode,
                }
                $.ajax({
                    url: '@ViewBag.FoundationWrite' + "/api/ProductType/PerformPulls",
                    data: JSON.stringify(data),
                    type: 'post',
                    async: false,
                    dataType: 'json',
                    contentType: 'application/json',
                    success: res => {
                        if (res.code > 0) {
                            alert("执行领出成功!");
                            location.reload();
                        }
                        else {
                            alert("执行领出失败!");
                        }
                    }
                });
            }

        }

        //审批
        function Steat(pickingStatus) {
            var selectedCheckboxes = $(': checkbox: gt(0): checked');
            if (selectedCheckboxes.length == 0) {
                1ayer.msg('请选择要审核的记录’);
                        return;
            }
            var ids = "";
            selectedCheckboxes.each(function () {
                ids += $(this).va1()
            })
            ids = ids.substring(0, ids.length - 1);
            $.post({
                url:"",
                data: JSON.stringify({
                    pickingId:ids,
                    pickingStatus: pickingStatus
                }),
                async:false,
                dataType:"json",
                contentType: "application/json",
                success:res=>{
                    if (res.code > 0) {
                        alert("修改成功!");
                        PickingLists(pageIndex, pageSize);
                    }
                    else if (res.data.pickingStatus == 1 || res.data.pickingStatus == 0) {
                        alert("已审批，请勿重复审批!");
                    }
                    else{
                        alert("修改成失败!");
                    }
                }
            })
            // let first = {
            //     pickingId: pickingId,
            //     pickingStatus: pickingStatus
            // }

            // if (data.pickingStatus == 0) {
            //     first.pickingStatus = 1;
            // }
            // if (data.pickingStatus == 1) {
            //     first.pickingStatus = 2;
            // }
            // if (data.pickingStatus == 2) {
            //     first.pickingStatus = 3;
            // }
            // if (data.pickingStatus == 3) {
            //     first.pickingStatus = 4;
            // }
            // console.log(first);
            // $.ajax({
            //     url: '@ViewBag.FoundationWrite' + "/api/ProductType/PinckingStatusAll",
            //     data: JSON.stringify(first),
            //     type: "post",
            //     async: true,
            //     dataType: "json",
            //     contentType: "application/json",
            //     success: res => {
            //         if (res.code > 0) {
            //             alert('修改成功');
            //         }
            //         else {
            //             alert('修改失败');
            //         }
            //     }

            // })


        }

    </script>
</body>
</html>
